package ooexercise04;
/*
public class Test {
    public static void main(String[] args) {
        Master master = new Master();
        Dog dogs = new Dog("小黑","黑",2);
        Fish fishes = new Fish("小金","金",1);
        Chick chicks = new Chick("小黄","黄",3);
        master.feed(dogs);
        master.feed(fishes);
        master.feed(chicks);

        Animal[] animals = new Animal[4];
        animals[0] = new Dog("小黑","黑",4);
        animals[1] = new Dog("小灰","灰",3);
        animals[2] = new Chick("小黄","黄",2);
        animals[3] = new Fish("小金","金",1);

        for (int i=0;i< animals.length;i++){
            System.out.println(animals[i].name);
            animals[i].eat();

            if(animals[i] instanceof Dog){
                Dog dog = (Dog) animals[i];
                dog.lookHome();
            }

            if(animals[i] instanceof Fish){
                Fish fish = (Fish) animals[i];
                fish.swim();
            }

            if (animals[i] instanceof Chick){
                Chick chick = (Chick) animals[i];
                chick.layEgg();
            }

            if (animals[i] instanceof Swim){
                Swim swim = (Swim) animals[i];
                swim.swim();
            }
        }

    }
}

 */
public class Test {
    public static void main(String[] args) {
        Master master = new Master();
        Dog dogs = new Dog("小黑","黑",2);
        Fish fishes = new Fish("小金","金",1);
        Chick chicks = new Chick("小黄","黄",3);
        master.feed(dogs);
        master.feed(fishes);
        master.feed(chicks);

        Animal[] animals = new Animal[4];
        animals[0] = new Dog("小黑", "黑", 4);
        animals[1] = new Dog("小灰", "灰", 3);
        animals[2] = new Chick("小黄","黄",2);
        animals[3] = new Fish("小金", "金", 1);

        for (int i = 0; i < animals.length; i++) {
            System.out.println(animals[i].name);
            animals[i].eat();

            if (animals[i] instanceof Dog) {
                Dog dog = (Dog) animals[i];
                dog.lookHome();
            }

            if (animals[i] instanceof Fish) {
                Fish fish = (Fish) animals[i];
                fish.swim();
            }

            if (animals[i] instanceof Chick) {
                Chick chick = (Chick) animals[i];
                chick.layEgg();
            }

            if (animals[i] instanceof Swim) {
                Swim swim = (Swim) animals[i];
                swim.swim();
            }
        }
    }
}